package cn.yeamin.spring.boot.controller;

import cn.yeamin.spring.boot.dao.UserMapper;
import cn.yeamin.spring.boot.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @packageName: 包名: cn.yeamin.spring.boot.controller
 * @classDesc: 类功能描述:(Mybatis测试)
 * @author: Administrator
 * @createTime: 2017/7/19 16:16
 * @version: v1.0
 * @copyright:奕明(上海)影视传媒有限公司
 */
@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;


    @GetMapping("/{name}")
    public User findByName(@PathVariable("name") String name)
    {
        return userMapper.findByName(name);
    }


    @GetMapping("/all")
    public List<User> findAll()
    {
        return userMapper.findAll();
    }

    @PostMapping("/save")
    public String save(User user) {
        try {
            userMapper.insert(user);
            return "添加成功";
        } catch (Exception e) {
            return "服务器错误,添加失败";
        }
    }




    @GetMapping("/delete/{id}")
    public String deleteById(@PathVariable("id") Integer id)
    {
        try {
            userMapper.deleteById(id);
            return "删除成功";
        } catch (Exception e) {
            return "服务器错误,删除失败";
        }
    }









}
